package com.buddy.sds.common.module;

import com.buddy.sds.common.ContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;

import java.util.Map;
@Slf4j
@Configuration
public class ModuleConfig {

    @Autowired
    public void checkModules(ContextHolder holder){

        ApplicationContext applicationContext = holder.getApplicationContext();

        if(applicationContext != null){
            Map<String,ModuleFlag> flagMap = applicationContext.getBeansOfType(ModuleFlag.class);

            flagMap.forEach((k,v)->{
                log.info("模块:{} 已加载",k);
                //TODO 将当前模块状态持久化到数据库,关闭一些未启用模块的访问权限
            });

        }
    }
}
